package C

/**
 * @author ljfirst
 * @version V1.0
 * @date 2023/7/4 21:23
 * @author-Email ljfirst@mail.ustc.edu.cn
 * @blogURL https://blog.csdn.net/ljfirst
 * @description 优先队列 Option
 * */
type Options func(*Option)

type Option struct {
	IsSmallHeap bool // 是否小顶堆
	LimitSize   int  // 限制容量-不可以扩容
	MaxSize     int  // 最大容量-可以扩容

	FromHighToLow bool // true表示从高到低排序,默认 false 表示从低到高排序
	HeadInsert    bool // 头插法，默认false是尾插法

	GT      GT
	Change  Change
	Compare Compare
}

func NewOptions(options ...Options) *Option {
	opt := &Option{
		IsSmallHeap: false,
		LimitSize:   0,
		MaxSize:     8,
		GT:          ArrayGT,
	}
	for _, option := range options {
		option(opt)
	}
	return opt
}

func WithHeadInsert(headInsert bool) Options {
	return func(o *Option) {
		o.HeadInsert = headInsert
	}

}
func WithFromHighToLow(fromHighToLow bool) Options {
	return func(o *Option) {
		o.FromHighToLow = fromHighToLow
	}
}

func WithQueueType(smallHeap bool) Options {
	return func(o *Option) {
		o.IsSmallHeap = smallHeap
	}
}

func WithMaxSize(maxSize int) Options {
	return func(o *Option) {
		o.MaxSize = maxSize
	}
}

func WithLimitSize(limitSize int) Options {
	return func(o *Option) {
		o.LimitSize = limitSize
	}
}

func WithGT(gt GT) Options {
	return func(o *Option) {
		o.GT = gt
	}
}

func WithChange(change Change) Options {
	return func(o *Option) {
		o.Change = change
	}
}

func WithCompare(compare Compare) Options {
	return func(o *Option) {
		o.Compare = compare
	}
}
